<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>


    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>

<body>
    <div class="container">
        <h2 class="page-header">基本使用</h2>
        <button class="btn btn-primary">
发送get
    </button>
        <button class="btn btn-waring">发送post</button>
        <button class="btn btn-success">发送put</button>
        <button class="btn btn-danger">发送delete</button>

    </div>

    <script>
        //获取按钮
        const buts = document.querySelectorAll("button");
        buts[0].onclick = function() {
            axios({
                method: 'get',
                url: "../../json/text.json",
            }).then(
                response => {
                    console.log(response);
                }
            )
        };
        buts[1].onclick = function() {
            axios({
                method: 'post',
                url: "../../json/posts",
                data: {
                    title: "天气真好",
                    author: "法外狂徒张三",
                    id: "1"
                }
            }).then(
                response => {
                    console.log(response);
                }
            );
        }
        buts[2].onclick = function() {
            axios({
                method: 'put', //更新
                url: "../../json/posts",
                data: {
                    title: "天气真好",
                    author: "法外狂徒张三",
                    id: "2"
                }
            }).then(
                response => {
                    console.log(response);
                }
            )
        };
        buts[3].onclick = function() {
            axios({
                method: 'delete',
                url: "../../json/posts/id",
                data: {
                    title: "天气真好",
                    author: "法外狂徒张三",
                    id: "1"
                }
            }).then(
                response => {
                    console.log(response);
                }
            )
        };
    </script>

</body>

</html>